<!DOCTYPE html>
<html lang="zh_CN">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<div id="demo"></div>
	<div id="test"></div>


	<script type="text/javascript">
		// 5:解决覆盖获取元素
		var A = function(selector) {
		    // 改进：利用 new 改变 this 指向
		    return new A.fn.init(selector);
		}
		A.fn = A.prototype = {
		    init: function(selector) {
		        this[0] = document.getElementById(selector);
		        this.length = 1;
		        console.log(this);
		        return this;
		    },
		    length: 2,
		    size: function() {
		        return this.length;
		    }
		}
		A('demo');
		A('test');
		// Uncaught TypeError: A(...).size is not a function
		A('demo').size();
	</script>
</body>
</html>